#define _CRT_SECURE_NO_WARNINGS
#include"sort.h"

void merge(array<int, 10>& arr, array<int, 10>* temp, int left, int right)
{
	if (left >= right)
		return;

	int mid = (left + right) >> 1;
	int left_end = mid;
	int right_begin = mid + 1;
	merge(arr, temp, left, left_end);
	merge(arr, temp, right_begin, right);
	int i = left;
	int begin = left;
	while (left <= left_end && right_begin <= right)
	{
		if (arr[left] < arr[right_begin])
			(*temp)[i++] = arr[left++];
		else
			(*temp)[i++] = arr[right_begin++];
	}
	while (left <= left_end)
		(*temp)[i++] = arr[left++];
	while (right_begin <= right)
		(*temp)[i++] = arr[right_begin++];
	for (int i = begin; i <= right; i++)
		arr[i] = (*temp)[i];
}

void merge_sort(array<int, 10>& arr)
{
	array<int, 10>* temp = new array<int, 10>;
	merge(arr, temp, 0, arr.size() - 1);
	delete[]temp;
}